<?php

namespace app\site\controller\store;

use app\common\exception\MiException;
use app\model\store\DistRewardLog;
use app\site\controller\AController;
use app\site\service\SiteAuthService;
use think\db\exception\DbException;

/**
 * 分销
 */
class DistController extends AController
{

    private int $siteId;

    /**
     * @throws MiException
     */
    protected function initialize()
    {
        $this->siteId = SiteAuthService::instance()->getSiteId();
    }

    /**
     * 佣金明细
     * @throws DbException
     */
    public function rewardLogPaginate(): \think\response\Json
    {
        $uid = $this->param('where.user_id');
        $where = [
            ['site_id', '=', $this->siteId]
        ];
        if ($uid) $where[] = ['user_id', '=', $uid];
        $query = DistRewardLog::where($where);
        return $this->jsonPaginate($query);
    }
}
